package com.jtjrenren.android.taxi.driver.core.other;

import android.content.Context;
import android.content.Intent;
import android.view.View;
import android.webkit.WebSettings;
import android.webkit.WebView;
import android.webkit.WebViewClient;
import android.widget.TextView;

import com.jtjrenren.android.taxi.driver.base.BaseActivity;
import com.jtjrenren.android.taxi.driver.R;

import butterknife.BindView;

/**
 * Created by Administrator on 2016/3/1.
 */
public class AppHtmlShowActivity extends BaseActivity {
    public static final String EXTRAS_URL = "url";
    public static final String EXTRAS_TITLE = "title";
    @BindView(R.id.html_show_web)
    WebView wbView;

    private String title, url;

    public static Intent getDiyIntent(Context context, String url, String title) {
        Intent intent = new Intent(context, AppHtmlShowActivity.class);
        intent.putExtra("url", url);
        intent.putExtra("title", title);
        return intent;
    }

    @Override
    public int getLayoutID() {
        return R.layout.aty_app_showhtml;
    }

    @Override
    public void init() {
        if (getIntent().hasExtra(EXTRAS_TITLE)) {
            title = getIntent().getStringExtra(EXTRAS_TITLE);
        }
        if (getIntent().hasExtra(EXTRAS_URL)) {
            url = getIntent().getStringExtra(EXTRAS_URL);
        }

        ((TextView) findViewById(R.id.title_title)).setText(title);
        findViewById(R.id.title_back).setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                onBackPressed();
            }
        });

        WebSettings setting = wbView.getSettings();
        setting.setJavaScriptEnabled(true);//添加js支持

        wbView.loadUrl(url);
        wbView.setWebViewClient(new WebViewClient() {
            @Override
            public boolean shouldOverrideUrlLoading(WebView view, String url) {
                view.loadUrl(url);
                return true;
            }

            @Override
            public void onPageFinished(WebView view, String url) {
                super.onPageFinished(view, url);
            }
        });
    }
}
